package cn.nnb.control.cy;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.snow.order.biz.FoodBiz;
import com.snow.order.entity.Food;
import com.snow.order.log.Log;


public class foodSelect extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public foodSelect() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		this.doPost(request, response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=GBK");
		
		int allPage=0;
		String count = request.getParameter("radiobutton");
		//System.out.println("count是"+count);
		if(count.equals("名称搜索")){
			System.out.println("进入名称搜索");
			String name = request.getParameter("select");
			try{
				
		
				FoodBiz foodbiz=new FoodBiz();
						List<Food> foodlist=new ArrayList<Food>();
						 foodlist=foodbiz.getaFoodbyna(name);
						
						allPage=foodlist.size();
						
						request.setAttribute("food", foodlist);
						
						request.setAttribute("allPage", allPage);
						
						
						request.getRequestDispatcher("cy/Manage.jsp").forward(request, response);
					
				} catch (Exception e) {
					Log.logger.error(e.getMessage());
					request.setAttribute("errMsg","服务器繁忙。。。");
					request.getRequestDispatcher("/error.jsp").forward(request, response);
				}			
			
		}
		/*else if(count.equals("餐厅搜索")){
			System.out.println("进入餐厅搜索");
			String proname = new String(request.getParameter("select").getBytes("ISO-8859-1"),"utf-8");
			try{
				//System.out.println("lalalalal");		
				foodBiz foodbiz=new foodBiz();
				System.out.println("proname是"+proname);
						List<Food> foodlist=foodbiz.getaFoodbypro(proname);
						allPage=foodlist.size();
						request.setAttribute("foodlist", foodlist);
						request.setAttribute("allPage", allPage);
						
						request.getRequestDispatcher("Manage.jsp").forward(request, response);
					
				} catch (Exception e) {
					Log.logger.error(e.getMessage());
					request.setAttribute("errMsg","服务器繁忙。。。");
					request.getRequestDispatcher("/error.jsp").forward(request, response);
				}			
			
			
		}*/
		else if(count.equals("折扣搜索")){
			System.out.println("进入折扣搜索");
			String discount = new String(request.getParameter("discountselect").getBytes("ISO-8859-1"),"utf-8");
			System.out.println("discount为"+discount);
			double dis=Double.parseDouble(discount);
			System.out.println("dis为"+dis);
			try{
				//System.out.println("lalalalal");		
				FoodBiz foodbiz=new FoodBiz();
						List<Food> foodlist=foodbiz.getaFoodbycou(dis);
						allPage=foodlist.size();
						System.out.println(allPage+"DDDDDDDD");
						request.setAttribute("foodlist", foodlist);
						request.setAttribute("allPage", allPage);
						request.getRequestDispatcher("cy/Manage.jsp").forward(request, response);
					
				} catch (Exception e) {
					Log.logger.error(e.getMessage());
					e.printStackTrace();
					request.setAttribute("errMsg","服务器繁忙。。。");
					request.getRequestDispatcher("/error.jsp").forward(request, response);
				}			
			
			
			
		}
		else{
			System.out.println("进入全部搜索");
			request.getRequestDispatcher("information").forward(request, response);
			
		}
		
		
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
